package com.seele.tigerwallet.ui.adapter;

import android.content.res.Resources;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seele.tigerwallet.R;
import com.seele.tigerwallet.model.MarketModel;
import com.seele.tigerwallet.model.UserInfo;
import com.seele.tigerwallet.ui.manager.GlideManager;
import com.seele.tigerwallet.ui.utils.DataUtils;
import com.seele.tigerwallet.ui.utils.SPUtils;
import com.seele.tigerwallet.ui.utils.TypefaceUtils;

import java.util.List;

public class MarketAdapter extends BaseItemDraggableAdapter<MarketModel, BaseViewHolder> {

    public MarketAdapter(List<MarketModel> data) {
        super(R.layout.item_market,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MarketModel item) {
        try {
            if (!TextUtils.isEmpty(item.symbol)) {
                helper.setText(R.id.token_name_tv, item.symbol);
            }
            //设置价格


            //todo
            helper.setText(R.id.token_price_tv, DataUtils.getMarketTotal(item.price));

            String change;
            if (!TextUtils.isEmpty(item.change)) {
                change = item.change;
                double parseDouble = Double.parseDouble(change);
                if (parseDouble == 0) {
                    change = change + "%";
                    helper.setBackgroundRes(R.id.token_increase_tv, R.drawable.gray_textview_round);
                } else if (parseDouble > 0) {
                    change = "+" + change + "%";
                    helper.setBackgroundRes(R.id.token_increase_tv, R.drawable.green_textview_round);
                } else if (parseDouble < 0) {
                    change = change + "%";
                    helper.setBackgroundRes(R.id.token_increase_tv, R.drawable.red_textview_round);
                }
                helper.setText(R.id.token_increase_tv, change);
            } else {
                change = 0 + "%";
                helper.setBackgroundRes(R.id.token_increase_tv, R.drawable.gray_textview_round);
                helper.setText(R.id.token_increase_tv, change);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
